﻿using System;

namespace datastruct
{
    public class Stack<T>
    {
        private T[] data;
        private int top;
        private int size;

        public Stack(int size)
        {
            this.size = size;
            this.top = -1;
            this.data = new T[size];
        }


        public void Push(T item)
        {
            if (top == size - 1)
            {
                throw new ArgumentOutOfRangeException();
            }
            this.top++;
            this.data[top] = item;

        }

        public T Peak()
        {
            if (this.isEmpty())
            {
                throw new ArgumentOutOfRangeException();
            }

            return data[top];
        }

        public T Pop()
        {
            if (this.isEmpty())
            {
                throw new ArgumentOutOfRangeException();
            }
            T e = data[top];
            this.top--;
            return e;
        }

        public Boolean isEmpty()
        {
            return this.top == -1;
        }

        public void Clear()
        {
            top = -1;
        }
    }
}